﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class FormRepClients : Form
    {
        private BindingSource bindingSource = new BindingSource();
        private SqlDataAdapter dataAdapter = new SqlDataAdapter();

        public FormRepClients()
        {
            InitializeComponent();
        }

        private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                //Traitement
            }
        }
     
        private void FormRepClients_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = bindingSource;
            GetData("SELECT id_client, nom, prenom, dateNaissance, adresse, localite, codepostal, numTelephone " 
                     +"FROM Client");
        }

        private void GetData(string selectCommand)
        {
            try
            {
                String connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Users\Mathieu\Documents\Visual Studio 2010\Projects\pCamping\WindowsFormsApplication1\WindowsFormsApplication1\Database1.mdf';Integrated Security=True;Connect Timeout=30;User Instance=True";
                dataAdapter = new SqlDataAdapter(selectCommand, connectionString);
                SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
                DataTable table = new DataTable();
                table.Locale = System.Globalization.CultureInfo.InvariantCulture;
                dataAdapter.Fill(table);
                bindingSource.DataSource = table;
            }
            catch (SqlException e)
            {
                MessageBox.Show(e.Message);
            }
        }
       
    }
}
